import { http } from '@kit.NetworkKit';
import { ResponseData } from '../model/ResponseData'
import { JSON } from '@kit.ArkTS';

export const checkToken = (): Promise<ResponseData> => {
    return new Promise<ResponseData>((resolve, reject) => {
        const token = '' // 获取本地存储token
        const httpRequest = http.createHttp()
        httpRequest.request('http://192.168.0.99:8081/user/checkToken', {
            method: http.RequestMethod.GET,
            header: {
                'Content-Type': 'application/json',
                'token': token
            }
        }).then((data: http.HttpResponse) => {
            if (data.responseCode == 200) {
                const resultObj = JSON.parse(data.result as string) as ResponseData
                resolve(resultObj)
            }
        }).catch((error: Error) => {
            reject(JSON.stringify(error))
        })
    })
}